home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 September / Enter 09 2006.iso / Internet / SpamExperts Home 1.1 / SpamExperts Home.exe / lib / spamexperts.modules / zope / interface / interfaces.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-07-14  |  24.0 KB  |  723 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. '''Interface Package Interfaces
  5.  
  6. $Id: interfaces.py 27082 2004-08-12 20:03:58Z srichter $
  7. '''
  8. from zope.interface import Interface
  9. from zope.interface.interface import Attribute
  10.  
  11. class IElement(Interface):
  12.     '''Objects that have basic documentation and tagged values.
  13.     '''
  14.     __name__ = Attribute('__name__', 'The object name')
  15.     __doc__ = Attribute('__doc__', 'The object doc string')
  16.     
  17.     def getTaggedValue(tag):
  18.         """Returns the value associated with 'tag'.
  19.  
  20.         Raise a KeyError of the tag isn't set
  21.         """
  22.         pass
  23.  
  24.     
  25.     def queryTaggedValue(tag, default = None):
  26.         """Returns the value associated with 'tag'.
  27.  
  28.         Return the default value of the tag isn't set.
  29.         """
  30.         pass
  31.  
  32.     
  33.     def getTaggedValueTags():
  34.         '''Returns a list of all tags.'''
  35.         pass
  36.  
  37.     
  38.     def setTaggedValue(tag, value):
  39.         """Associates 'value' with 'key'."""
  40.         pass
  41.  
  42.  
  43.  
  44. class IAttribute(IElement):
  45.     '''Attribute descriptors'''
  46.     pass
  47.  
  48.  
  49. class IMethod(IAttribute):
  50.     '''Method attributes
  51.     '''
  52.     
  53.     def getSignatureInfo():
  54.         """Returns the signature information.
  55.  
  56.         This method returns a dictionary with the following keys:
  57.  
  58.         o `positional` - All positional arguments.
  59.  
  60.         o `required` - A list of all required arguments.
  61.  
  62.         o `optional` - A list of all optional arguments.
  63.  
  64.         o `varargs' - The name of the varargs argument.
  65.  
  66.         o `kwargs` - The name of the kwargs argument.
  67.         """
  68.         pass
  69.  
  70.     
  71.     def getSignatureString():
  72.         """Return a signature string suitable for inclusion in documentation.
  73.  
  74.         This method returns the function signature string. For example, if you
  75.         have `func(a, b, c=1, d='f')`, then the signature string is `(a, b,
  76.         c=1, d='f')`.
  77.         """
  78.         pass
  79.  
  80.  
  81.  
  82. class ISpecification(Interface):
  83.     '''Object Behavioral specifications
  84.     '''
  85.     
  86.     def extends(other, strict = True):
  87.         """Test whether a specification extends another
  88.  
  89.         The specification extends other if it has other as a base
  90.         interface or if one of it's bases extends other.
  91.  
  92.         If strict is false, then the specification extends itself.
  93.         
  94.         """
  95.         pass
  96.  
  97.     
  98.     def isOrExtends(other):
  99.         '''Test whether the specification is or extends another
  100.         '''
  101.         pass
  102.  
  103.     
  104.     def weakref(callback = None):
  105.         '''Return a weakref to the specification
  106.  
  107.         This method is, regrettably, needed to allow weakrefs to be
  108.         computed to security-proxied specifications.  While the
  109.         zope.interface package does not require zope.security or
  110.         zope.proxy, it has to be able to coexist with it.
  111.  
  112.         '''
  113.         pass
  114.  
  115.     __bases__ = Attribute('Base specifications\n\n    A tuple if specifications from which this specification is\n    directly derived.\n\n    ')
  116.     __sro__ = Attribute("Specification-resolution order\n\n    A tuple of the specification and all of it's ancestor\n    specifications from most specific to least specific.\n\n    (This is similar to the method-resolution order for new-style classes.)\n    ")
  117.     
  118.     def get(name, default = None):
  119.         '''Look up the description for a name
  120.  
  121.         If the named attribute is not defined, the default is
  122.         returned.
  123.         '''
  124.         pass
  125.  
  126.  
  127.  
  128. class IInterface(ISpecification, IElement):
  129.     '''Interface objects
  130.  
  131.     Interface objects describe the behavior of an object by containing
  132.     useful information about the object.  This information includes:
  133.  
  134.       o Prose documentation about the object.  In Python terms, this
  135.         is called the "doc string" of the interface.  In this element,
  136.         you describe how the object works in prose language and any
  137.         other useful information about the object.
  138.  
  139.       o Descriptions of attributes.  Attribute descriptions include
  140.         the name of the attribute and prose documentation describing
  141.         the attributes usage.
  142.  
  143.       o Descriptions of methods.  Method descriptions can include:
  144.  
  145.         o Prose "doc string" documentation about the method and its
  146.           usage.
  147.  
  148.         o A description of the methods arguments; how many arguments
  149.           are expected, optional arguments and their default values,
  150.           the position or arguments in the signature, whether the
  151.           method accepts arbitrary arguments and whether the method
  152.           accepts arbitrary keyword arguments.
  153.  
  154.       o Optional tagged data.  Interface objects (and their attributes and
  155.         methods) can have optional, application specific tagged data
  156.         associated with them.  Examples uses for this are examples,
  157.         security assertions, pre/post conditions, and other possible
  158.         information you may want to associate with an Interface or its
  159.         attributes.
  160.  
  161.     Not all of this information is mandatory.  For example, you may
  162.     only want the methods of your interface to have prose
  163.     documentation and not describe the arguments of the method in
  164.     exact detail.  Interface objects are flexible and let you give or
  165.     take any of these components.
  166.  
  167.     Interfaces are created with the Python class statement using
  168.     either Interface.Interface or another interface, as in::
  169.  
  170.       from zope.interface import Interface
  171.  
  172.       class IMyInterface(Interface):
  173.         \'\'\'Interface documentation
  174.         \'\'\'
  175.  
  176.         def meth(arg1, arg2):
  177.             \'\'\'Documentation for meth
  178.             \'\'\'
  179.  
  180.         # Note that there is no self argument
  181.  
  182.      class IMySubInterface(IMyInterface):
  183.         \'\'\'Interface documentation
  184.         \'\'\'
  185.  
  186.         def meth2():
  187.             \'\'\'Documentation for meth2
  188.             \'\'\'
  189.  
  190.     You use interfaces in two ways:
  191.  
  192.     o You assert that your object implement the interfaces.
  193.  
  194.       There are several ways that you can assert that an object
  195.       implements an interface::
  196.  
  197.       1. Call zope.interface.implements in your class definition.
  198.  
  199.       2. Call zope.interfaces.directlyProvides on your object.
  200.  
  201.       3. Call \'zope.interface.classImplements\' to assert that instances
  202.          of a class implement an interface.
  203.  
  204.          For example::
  205.  
  206.            from zope.interface import classImplements
  207.  
  208.            classImplements(some_class, some_interface)
  209.  
  210.          This approach is useful when it is not an option to modify
  211.          the class source.  Note that this doesn\'t affect what the
  212.          class itself implements, but only what its instances
  213.          implement.
  214.  
  215.     o You query interface meta-data. See the IInterface methods and
  216.       attributes for details.
  217.  
  218.     '''
  219.     
  220.     def providedBy(object):
  221.         '''Test whether the interface is implemented by the object
  222.  
  223.         Return true of the object asserts that it implements the
  224.         interface, including asserting that it implements an extended
  225.         interface.
  226.         '''
  227.         pass
  228.  
  229.     
  230.     def implementedBy(class_):
  231.         '''Test whether the interface is implemented by instances of the class
  232.  
  233.         Return true of the class asserts that its instances implement the
  234.         interface, including asserting that they implement an extended
  235.         interface.
  236.         '''
  237.         pass
  238.  
  239.     
  240.     def names(all = False):
  241.         '''Get the interface attribute names
  242.  
  243.         Return a sequence of the names of the attributes, including
  244.         methods, included in the interface definition.
  245.  
  246.         Normally, only directly defined attributes are included. If
  247.         a true positional or keyword argument is given, then
  248.         attributes defined by base classes will be included.
  249.         '''
  250.         pass
  251.  
  252.     
  253.     def namesAndDescriptions(all = False):
  254.         '''Get the interface attribute names and descriptions
  255.  
  256.         Return a sequence of the names and descriptions of the
  257.         attributes, including methods, as name-value pairs, included
  258.         in the interface definition.
  259.  
  260.         Normally, only directly defined attributes are included. If
  261.         a true positional or keyword argument is given, then
  262.         attributes defined by base classes will be included.
  263.         '''
  264.         pass
  265.  
  266.     
  267.     def __getitem__(name):
  268.         '''Get the description for a name
  269.  
  270.         If the named attribute is not defined, a KeyError is raised.
  271.         '''
  272.         pass
  273.  
  274.     
  275.     def validateInvariants(obj, errors = None):
  276.         '''Validate invariants
  277.  
  278.         Validate object to defined invariants.  If errors is None,
  279.         raises first Invalid error; if errors is a list, appends all errors
  280.         to list, then raises Invalid with the errors as the first element
  281.         of the "args" tuple.'''
  282.         pass
  283.  
  284.     
  285.     def __contains__(name):
  286.         '''Test whether the name is defined by the interface'''
  287.         pass
  288.  
  289.     
  290.     def __iter__():
  291.         '''Return an iterator over the names defined by the interface
  292.  
  293.         The names iterated include all of the names defined by the
  294.         interface directly and indirectly by base interfaces.
  295.         '''
  296.         pass
  297.  
  298.     __module__ = Attribute('The name of the module defining the interface')
  299.  
  300.  
  301. class IDeclaration(ISpecification):
  302.     '''Interface declaration
  303.  
  304.     Declarations are used to express the interfaces implemented by
  305.     classes or provided by objects.
  306.     
  307.     '''
  308.     
  309.     def __contains__(interface):
  310.         '''Test whether an interface is in the specification
  311.  
  312.         Return true if the given interface is one of the interfaces in
  313.         the specification and false otherwise.
  314.         '''
  315.         pass
  316.  
  317.     
  318.     def __iter__():
  319.         '''Return an iterator for the interfaces in the specification
  320.         '''
  321.         pass
  322.  
  323.     
  324.     def flattened():
  325.         '''Return an iterator of all included and extended interfaces
  326.  
  327.         An iterator is returned for all interfaces either included in
  328.         or extended by interfaces included in the specifications
  329.         without duplicates. The interfaces are in "interface
  330.         resolution order". The interface resolution order is such that
  331.         base interfaces are listed after interfaces that extend them
  332.         and, otherwise, interfaces are included in the order that they
  333.         were defined in the specification.
  334.         '''
  335.         pass
  336.  
  337.     
  338.     def __sub__(interfaces):
  339.         '''Create an interface specification with some interfaces excluded
  340.  
  341.         The argument can be an interface or an interface
  342.         specifications.  The interface or interfaces given in a
  343.         specification are subtracted from the interface specification.
  344.  
  345.         Removing an interface that is not in the specification does
  346.         not raise an error. Doing so has no effect.
  347.  
  348.         Removing an interface also removes sub-interfaces of the interface.
  349.  
  350.         '''
  351.         pass
  352.  
  353.     
  354.     def __add__(interfaces):
  355.         '''Create an interface specification with some interfaces added
  356.  
  357.         The argument can be an interface or an interface
  358.         specifications.  The interface or interfaces given in a
  359.         specification are added to the interface specification.
  360.  
  361.         Adding an interface that is already in the specification does
  362.         not raise an error. Doing so has no effect.
  363.         '''
  364.         pass
  365.  
  366.     
  367.     def __nonzero__():
  368.         '''Return a true value of the interface specification is non-empty
  369.         '''
  370.         pass
  371.  
  372.  
  373.  
  374. class IInterfaceDeclaration(Interface):
  375.     """Declare and check the interfaces of objects
  376.  
  377.     The functions defined in this interface are used to declare the
  378.     interfaces that objects provide and to query the interfaces that have
  379.     been declared.
  380.  
  381.     Interfaces can be declared for objects in two ways:
  382.  
  383.     - Interfaces are declared for instances of the object's class
  384.  
  385.     - Interfaces are declared for the object directly.
  386.  
  387.     The interfaces declared for an object are, therefore, the union of
  388.     interfaces declared for the object directly and the interfaces
  389.     declared for instances of the object's class.
  390.  
  391.     Note that we say that a class implements the interfaces provided
  392.     by it's instances.  An instance can also provide interfaces
  393.     directly.  The interfaces provided by an object are the union of
  394.     the interfaces provided directly and the interfaces implemented by
  395.     the class.
  396.     """
  397.     
  398.     def providedBy(ob):
  399.         """Return the interfaces provided by an object
  400.  
  401.         This is the union of the interfaces directly provided by an
  402.         object and interfaces implemented by it's class.
  403.  
  404.         The value returned is an IDeclaration.
  405.         """
  406.         pass
  407.  
  408.     
  409.     def implementedBy(class_):
  410.         """Return the interfaces implemented for a class' instances
  411.  
  412.         The value returned is an IDeclaration.
  413.         """
  414.         pass
  415.  
  416.     
  417.     def classImplements(class_, *interfaces):
  418.         '''Declare additional interfaces implemented for instances of a class
  419.  
  420.         The arguments after the class are one or more interfaces or
  421.         interface specifications (IDeclaration objects).
  422.  
  423.         The interfaces given (including the interfaces in the
  424.         specifications) are added to any interfaces previously
  425.         declared.
  426.  
  427.         Consider the following example::
  428.  
  429.           class C(A, B):
  430.              ...
  431.  
  432.           classImplements(C, I1, I2)
  433.  
  434.  
  435.         Instances of ``C`` provide ``I1``, ``I2``, and whatever interfaces
  436.         instances of ``A`` and ``B`` provide.
  437.         '''
  438.         pass
  439.  
  440.     
  441.     def classImplementsOnly(class_, *interfaces):
  442.         '''Declare the only interfaces implemented by instances of a class
  443.  
  444.         The arguments after the class are one or more interfaces or
  445.         interface specifications (IDeclaration objects).
  446.  
  447.         The interfaces given (including the interfaces in the
  448.         specifications) replace any previous declarations.
  449.  
  450.         Consider the following example::
  451.  
  452.           class C(A, B):
  453.              ...
  454.  
  455.           classImplements(C, IA, IB. IC)
  456.           classImplementsOnly(C. I1, I2)
  457.  
  458.         Instances of ``C`` provide only ``I1``, ``I2``, and regardless of
  459.         whatever interfaces instances of ``A`` and ``B`` implement.
  460.         '''
  461.         pass
  462.  
  463.     
  464.     def directlyProvidedBy(object):
  465.         '''Return the interfaces directly provided by the given object
  466.  
  467.         The value returned is an IDeclaration.
  468.         '''
  469.         pass
  470.  
  471.     
  472.     def directlyProvides(object, *interfaces):
  473.         """Declare interfaces declared directly for an object
  474.  
  475.         The arguments after the object are one or more interfaces or
  476.         interface specifications (IDeclaration objects).
  477.  
  478.         The interfaces given (including the interfaces in the
  479.         specifications) replace interfaces previously
  480.         declared for the object.
  481.  
  482.         Consider the following example::
  483.  
  484.           class C(A, B):
  485.              ...
  486.  
  487.           ob = C()
  488.           directlyProvides(ob, I1, I2)
  489.  
  490.         The object, ``ob`` provides ``I1``, ``I2``, and whatever interfaces
  491.         instances have been declared for instances of ``C``.
  492.  
  493.         To remove directly provided interfaces, use ``directlyProvidedBy`` and
  494.         subtract the unwanted interfaces. For example::
  495.  
  496.           directlyProvides(ob, directlyProvidedBy(ob)-I2)
  497.  
  498.         removes I2 from the interfaces directly provided by
  499.         ``ob``. The object, ``ob`` no longer directly provides ``I2``,
  500.         although it might still provide ``I2`` if it's class
  501.         implements ``I2``.
  502.  
  503.         To add directly provided interfaces, use ``directlyProvidedBy`` and
  504.         include additional interfaces.  For example::
  505.  
  506.           directlyProvides(ob, directlyProvidedBy(ob), I2)
  507.  
  508.         adds I2 to the interfaces directly provided by ob.
  509.         """
  510.         pass
  511.  
  512.     
  513.     def implements(*interfaces):
  514.         '''Declare interfaces implemented by instances of a class
  515.  
  516.         This function is called in a class definition.
  517.  
  518.         The arguments are one or more interfaces or interface
  519.         specifications (IDeclaration objects).
  520.  
  521.         The interfaces given (including the interfaces in the
  522.         specifications) are added to any interfaces previously
  523.         declared.
  524.  
  525.         Previous declarations include declarations for base classes
  526.         unless implementsOnly was used.
  527.  
  528.         This function is provided for convenience. It provides a more
  529.         convenient way to call classImplements. For example::
  530.  
  531.           implements(I1)
  532.  
  533.         is equivalent to calling::
  534.  
  535.           classImplements(C, I1)
  536.  
  537.         after the class has been created.
  538.  
  539.         Consider the following example::
  540.  
  541.           class C(A, B):
  542.             implements(I1, I2)
  543.  
  544.  
  545.         Instances of ``C`` implement ``I1``, ``I2``, and whatever interfaces
  546.         instances of ``A`` and ``B`` implement.
  547.         '''
  548.         pass
  549.  
  550.     
  551.     def implementsOnly(*interfaces):
  552.         '''Declare the only interfaces implemented by instances of a class
  553.  
  554.         This function is called in a class definition.
  555.  
  556.         The arguments are one or more interfaces or interface
  557.         specifications (IDeclaration objects).
  558.  
  559.         Previous declarations including declarations for base classes
  560.         are overridden.
  561.  
  562.         This function is provided for convenience. It provides a more
  563.         convenient way to call classImplementsOnly. For example::
  564.  
  565.           implementsOnly(I1)
  566.  
  567.         is equivalent to calling::
  568.  
  569.           classImplementsOnly(I1)
  570.  
  571.         after the class has been created.
  572.  
  573.         Consider the following example::
  574.  
  575.           class C(A, B):
  576.             implementsOnly(I1, I2)
  577.  
  578.  
  579.         Instances of ``C`` implement ``I1``, ``I2``, regardless of what
  580.         instances of ``A`` and ``B`` implement.
  581.         '''
  582.         pass
  583.  
  584.     
  585.     def classProvides(*interfaces):
  586.         """Declare interfaces provided directly by a class
  587.  
  588.         This function is called in a class definition.
  589.  
  590.         The arguments are one or more interfaces or interface
  591.         specifications (IDeclaration objects).
  592.  
  593.         The given interfaces (including the interfaces in the
  594.         specifications) are used to create the class's direct-object
  595.         interface specification.  An error will be raised if the module
  596.         class has an direct interface specification.  In other words, it is
  597.         an error to call this function more than once in a class
  598.         definition.
  599.  
  600.         Note that the given interfaces have nothing to do with the
  601.         interfaces implemented by instances of the class.
  602.  
  603.         This function is provided for convenience. It provides a more
  604.         convenient way to call directlyProvides for a class. For example::
  605.  
  606.           classProvides(I1)
  607.  
  608.         is equivalent to calling::
  609.  
  610.           directlyProvides(theclass, I1)
  611.  
  612.         after the class has been created.
  613.         """
  614.         pass
  615.  
  616.     
  617.     def moduleProvides(*interfaces):
  618.         """Declare interfaces provided by a module
  619.  
  620.         This function is used in a module definition.
  621.  
  622.         The arguments are one or more interfaces or interface
  623.         specifications (IDeclaration objects).
  624.  
  625.         The given interfaces (including the interfaces in the
  626.         specifications) are used to create the module's direct-object
  627.         interface specification.  An error will be raised if the module
  628.         already has an interface specification.  In other words, it is
  629.         an error to call this function more than once in a module
  630.         definition.
  631.  
  632.         This function is provided for convenience. It provides a more
  633.         convenient way to call directlyProvides for a module. For example::
  634.  
  635.           moduleImplements(I1)
  636.  
  637.         is equivalent to::
  638.  
  639.           directlyProvides(sys.modules[__name__], I1)
  640.         """
  641.         pass
  642.  
  643.     
  644.     def Declaration(*interfaces):
  645.         '''Create an interface specification
  646.  
  647.         The arguments are one or more interfaces or interface
  648.         specifications (IDeclaration objects).
  649.  
  650.         A new interface specification (IDeclaration) with
  651.         the given interfaces is returned.
  652.         '''
  653.         pass
  654.  
  655.  
  656.  
  657. class IAdapterRegistry(Interface):
  658.     '''Provide an interface-based registry for adapters
  659.  
  660.     This registry registers objects that are in some sense "from" a
  661.     sequence of specification to an interface and a name.
  662.  
  663.     No specific semantics are assumed for the registered objects,
  664.     however, the most common application will be to register factories
  665.     that adapt objects providing required specifications to a provided
  666.     interface. 
  667.     
  668.     '''
  669.     
  670.     def register(required, provided, name, value):
  671.         '''Register a value
  672.  
  673.         A value is registered for a *sequence* of required specifications, a
  674.         provided interface, and a name.
  675.         '''
  676.         pass
  677.  
  678.     
  679.     def lookup(required, provided, name, default = None):
  680.         '''Lookup a value
  681.  
  682.         A value is looked up based on a *sequence* of required
  683.         specifications, a provided interface, and a name.
  684.         '''
  685.         pass
  686.  
  687.     
  688.     def lookupAll(required, provided):
  689.         '''Find all adapters from the required to the provided interfaces
  690.  
  691.         An iterable object is returned that provides name-value two-tuples.
  692.         '''
  693.         pass
  694.  
  695.     
  696.     def names(required, provided):
  697.         '''Return the names for which there are registered objects
  698.         '''
  699.         pass
  700.  
  701.     
  702.     def subscribe(required, provided, subscriber):
  703.         '''Register a subscriber
  704.  
  705.         A subscriber is registered for a *sequence* of required
  706.         specifications, a provided interface, and a name.
  707.  
  708.         Multiple subscribers may be registered for the same (or
  709.         equivalent) interfaces.
  710.         '''
  711.         pass
  712.  
  713.     
  714.     def subscriptions(required, provided):
  715.         '''Get a sequence of subscribers
  716.  
  717.         Subscribers for a *sequence* of required interfaces, and a provided
  718.         interface are returned.
  719.         '''
  720.         pass
  721.  
  722.  
  723.